<card id="index" title="MRAK">
<?php
$query = "SELECT
      `id`
    FROM
      quest.game
    WHERE
      `status`=3
    LIMIT
      1;";
$sql = mysql_query($query) or die(mysql_error());
if (mysql_num_rows($sql)<1){


$query = "SELECT
      `id`
    FROM
      quest.game
    WHERE
      `start_date` <= NOW() AND `status`=2
    ORDER BY
      `start_date`
    LIMIT
      1;";
$sql = mysql_query($query) or die(mysql_error());
if (mysql_num_rows($sql)==1){
$sql=mysql_fetch_assoc($sql);
$query = "UPDATE
      quest.game
      SET
      `status`=3
        WHERE `id`={$sql['id']};";
mysql_query($query) or die(mysql_error());    
 echo "НАЧАЛИ!";   
}
}

$query = "SELECT
      `id`, `title`, DATE_FORMAT(`start_date`, '%d.%m.%Y %H:%i') as `start_date`
    FROM
      quest.game
    WHERE
      (`start_date` >= NOW() AND `status`=1 OR `status`=2)
    ORDER BY
      `start_date`
    LIMIT 1;";
$sql = mysql_query($query) or die(mysql_error());

if (mysql_num_rows($sql)==1){
$sql=mysql_fetch_assoc($sql);
print "Ближайшая игра \"{$sql['title']}\" состоится: {$sql['start_date']}";
}
else
{
    print 'Нет запланированных игр.';
}

?>
<a href="index.php?mode=test"><br />Проверить работу устройства.</a>
</card>

